﻿using DAMS.Models;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;

namespace DAMS.Service
{
    public interface IRepository
    {
        #region Category 操作
        /// <summary>
        /// 通过ID删除一个分类
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Result<Category> CategoryDeleteByID(int id);
        /// <summary>
        /// 更新一个分类
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Result<Category> CategoryUpdate(Category entity);
        /// <summary>
        /// 更新一个分类
        /// </summary>
        /// <param name="id">分类ID</param>
        /// <param name="name">分类名</param>
        /// <param name="template">模版或Url</param>
        /// <param name="articleTemplate">内容页模版</param>
        /// <param name="desc">Html页面描述</param>
        /// <param name="keyword">Html页面关键字</param>
        /// <param name="content">内容</param>
        /// <param name="showtype">显示位置</param>
        /// <returns>返回结果，指示是否更新成功</returns>
        Result<Category> CategoryUpdate(int id, string name, string template, string articleTemplate, string desc, string keyword, string content, int showtype);
        /// <summary>
        /// 创建一个新分类
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Result<Category> CategoryCreate(Category entity);
        

        /// <summary>
        /// 通过ID获取一个分类
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Category CategoryGetByID(int id);
        /// <summary>
        /// 获取顶级分类
        /// </summary>
        /// <returns></returns>
        IEnumerable<Category> CategoryGetTop();

        /// <summary>
        /// 根据id获取子分类
        /// </summary>
        /// <param name="id"></param>
        /// <param name="isInThis">获取的自分类列表是否包含当前分类，默认包含</param>
        /// <param name="isAll">一个布尔值，指示是否获取全部子分类，False将只获取下一级子分类，默认为True</param>
        /// <returns></returns>
        IEnumerable<Category> CategoryGetChildListByID(int id, bool isInThis = true, bool isAll = true);


        /// <summary>
        /// 移动分类的排序
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="newOrder">新的排序位置</param>
        /// <returns></returns>
        Result<Category> CategoryOrderMove(Category entity, int newOrder);
        /// <summary>
        /// 移动分类的排序
        /// </summary>
        /// <param name="id"></param>
        /// <param name="newOrder">新的排序位置</param>
        /// <returns></returns>
        Result<Category> CategoryOrderMove(int id, int newOrder);

        /// <summary>
        /// 获取全部分类
        /// </summary>
        /// <returns></returns>
        IEnumerable<Category> CategoryGetAll();

        /// <summary>
        /// 获取父子映射过的全部分类
        /// </summary>
        /// <returns></returns>
        Category CategoryMapGetAll();
        

        /// <summary>
        /// 获取全部分类精简形式
        /// </summary>
        /// <returns></returns>
        CategoryCut CategoryCutGetAll();

        string CategoryCutGetJson();
        /// <summary>
        /// 获取分类的树形表示。
        /// </summary>
        /// <returns></returns>
        Category CategoryGetTree();
        /// <summary>
        /// 获取树形目录的JSON
        /// </summary>
        /// <returns></returns>
        string CategoryGetTreeJson();
        /// <summary>
        /// 获取树形目录JSon
        /// </summary>
        /// <param name="pairs"></param>
        /// <returns></returns>
        string CategoryGetTreeJson(Dictionary<string, string> pairs);
        /// <summary>
        /// 获取模板列表
        /// </summary>
        /// <param name="contentRootPath">项目目录</param>
        /// <returns>json字符串</returns>
        string CategoryGetTemplateJson(string contentRootPath);
        /// <summary>
        /// 根据ID获取父分类
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Category CategoryGetParentByID(int id);

        /// <summary>
        /// 按ID获取分类的所有父分类.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        IEnumerable<Category> CategoryGetParentListByID(int id);

        /// <summary>
        /// 移动分类在兄弟分类中的排序位置
        /// </summary>
        /// <param name="id">要移动的分类ID</param>
        /// <param name="newid">将要移动到新位置所处的分类ID</param>
        /// <returns>返回操作是否成功，及受影响的记录数</returns>
        Result<Category> CategoryMove(int id,int newid);
        #endregion

        #region Tag 操作
        /// <summary>
        /// 添加新标签
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        Result<Tag> TagCreate(Tag tag);
        Result<Tag> TagUpdate(Tag tag);
        Result<Tag> TagGet(string name);
        /// <summary>
        /// 根据页和页大小获取一定数量的标签
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        IEnumerable<Tag> TagGetListByPage(int page, int pagesize, string keyword = "");
        int TagGetCount(string keyword = "");
        /// <summary>
        /// 根据ID删除标签
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Result<Tag> TagDeleteByID(int id);
        #endregion

        #region ArticleTag
        Result<Article> Create(ArticleTag at);
        #endregion

        #region Article
        Result<Article> ArticleCreate(Article article);
        Article ArticleGetByID(int id);
        Result<Article> ArticleUpdate(Article article);
        /// <summary>
        /// 分页获取内容列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        List<Article> ArticleGetByPager(int pageIndex, int pageSize, Expression<Func<Article, bool>> lamband=null);
        #endregion
    }

}